package com.mxfcode.front.bbs_resource.service.impl;

import com.mxfcode.entity.BBSAttachment;
import com.mxfcode.entity.TSUser;
import com.mxfcode.front.bbs_login.mapper.LoginMapper;
import com.mxfcode.front.bbs_resource.mapper.AttachmentMapper;
import com.mxfcode.front.bbs_resource.mapper.ResourceMapper;
import com.mxfcode.front.bbs_resource.service.ResourceService;
import com.mxfcode.front.dto.ResourceDTO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @类名 ResourceServiceImpl
 * @描述 资源业务
 * @作者 mxf
 * @创建日期 2021-04-13 8:26
 **/
@Repository
public class ResourceServiceImpl implements ResourceService {

    @Resource
    private ResourceMapper resourceMapper;
    @Resource
    private AttachmentMapper attachmentMapper;
    @Resource
    private LoginMapper loginMapper;

    @Override
    public List<ResourceDTO> selectResource(String userId, int offset, int limit, int i) {

        List<ResourceDTO> resourceList = resourceMapper.selectResource(userId, offset, limit);
        if(resourceList != null && resourceList.size() > 0){
            resourceList.stream().forEach(resourceDTO->{
                List<BBSAttachment> attachmentList = attachmentMapper.getAttachmentList(resourceDTO.getId());
                resourceDTO.setAttachmentList(attachmentList);
            });
        }
        return resourceList;
    }

    @Override
    public int selectResourceRows(String id) {
        return resourceMapper.selectResourceRows(id);
    }

}
